package Users;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

import javax.swing.text.DateFormatter;

public class user {
	
	private String Name = "";
	private String Surname = "";
	private String Pat = "";
	private Calendar Birthdate = null;
	private int Month = 0;
	private int Day = 0;
	private int Year = 0;
	private int age = 0;
	private StringBuilder FormattedDate = null;
	
	public void SetName(String name)
	{
		Name = name;
	}
	
	public void SetSurname(String surname)
	{
		Surname = surname;
	}
	
	public void SetPat(String pat)
	{
		Pat = pat;
	}
	
	
	public void SetDate(Date date)
	{
		Birthdate = GregorianCalendar.getInstance();
		Birthdate.setTime(date);	
		
		Month = Birthdate.get(Calendar.MONTH);
		Day = Birthdate.get(Calendar.DAY_OF_MONTH);
		Year = Birthdate.get(Calendar.YEAR);
		FormattedDate = new StringBuilder(new SimpleDateFormat("dd MMM yyyy",new Locale("RU")).format(Birthdate));
		Date aDate = new Date(System.currentTimeMillis());
		Calendar calendar2 = GregorianCalendar.getInstance();
		calendar2.setTime(aDate);
		age = calendar2.get(Calendar.YEAR) - Birthdate.get(Calendar.YEAR);
	}
	
	public String GetName()
	{
		return Name;
	}
	
	public String GetSurname()
	{
		return Surname;
	}
	
	public String GetPat()
	{
		return Pat;
	}
	
	public Calendar GetDate()
	{
		return Birthdate;
	}
	
	public StringBuilder GetFormattedDate()
	{
		return FormattedDate;
	}
	
	public boolean Compare(user usr)
	{
		if(usr.Month == Month && usr.Day == Day)
			{return true;}
		else
			{return false;}
	}
	
	public void SetDay (int day)
	{
		Day = day;
		Birthdate.set(Calendar.DAY_OF_MONTH, day);
	}
	
	public void SetMonth (int month)
	{
		Month = month;
		Birthdate.set(Calendar.MONTH, month);
	}
	
	public void SetYear (int year)
	{
		Year = year;
		Birthdate.set(Calendar.YEAR, year);
	}
	
	public int GetDay()
	{
		return Day;
	}
	
	public int GetMonth()
	{
		return Month;
	}
	
	public int GetYear()
	{
		return Year;
	}
	
	public static user [] SortByAsc(user [] arr)
	{
		boolean swapped = true;
	      int j = 0;
	      user tmp;
	      while (swapped) {
	            swapped = false;
	            j++;
	            for (int i = 0; i < arr.length - j; i++) {                                       
	                  if (arr[i].Birthdate.before(arr[i + 1])) {                          
	                        tmp = arr[i];
	                        arr[i] = arr[i + 1];
	                        arr[i + 1] = tmp;
	                        swapped = true;
	                  }
	            }                
	      }
		return arr;
	}
	
	public static user [] SortByDesc(user [] arr)
	{
		boolean swapped = true;
	      int j = 0;
	      user tmp;
	      while (swapped) {
	            swapped = false;
	            j++;
	            for (int i = 0; i < arr.length - j; i++) {                                       
	                  if (arr[i].Birthdate.after((arr[i + 1]))) {                          
	                        tmp = arr[i];
	                        arr[i] = arr[i + 1];
	                        arr[i + 1] = tmp;
	                        swapped = true;
	                  }
	            }                
	      }
		return arr;
	}
	
	public int GetDaysB()
	{
		int days = 0;
		Date aDate = new Date(System.currentTimeMillis());
		Calendar calendar2 = GregorianCalendar.getInstance();
		calendar2.setTime(aDate);
		days = calendar2.get(Calendar.DAY_OF_YEAR) - Birthdate.get(Calendar.DAY_OF_YEAR);
		return days;
	}
}
